﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Guada
{
    public partial class FrmAsistenciaT : Plantilla
    {
        public FrmAsistenciaT()
        {
            InitializeComponent();
        }

        private void FrmAsistenciaT_Load(object sender, EventArgs e)
        {
            CargarDgTurnos("");
        }

        private void BtnBuscar_Click(object sender, EventArgs e)
        {
            FacProFacu.Turno turno = new FacProFacu.Turno();
            DataTable Dt = turno.GetTurnosAsigandos(txtNumDoc.Text).Tables["TURNOSA"];
        }

        private void BtnConfirmar_Click(object sender, EventArgs e)
        {
            try
            {
                int aux;
                FacProFacu.Turno turno = new FacProFacu.Turno();

                for (int i = 0; i < dgTurnos.Rows.Count; i++)
                {
                    if ((bool)this.dgTurnos.Rows[i].Cells[0].Value == true)
                    {
                        aux = turno.ConfirmarTurno(dgTurnos.Rows[i].Cells["ID"].ToString());
                        if (aux > 0)
                        {
                            CargarDgTurnos("");
                        }
                    }
                }
            }
            catch
            {

            }
        }

        private void BtnCancelar_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void CargarDgTurnos(string sParam)
        {
            try
            {
                FacProFacu.Turno turno = new FacProFacu.Turno();
                dgTurnos.DataSource = turno.GetTurnosAsigandos(sParam).Tables["TURNOSC"];

                DataGridViewColumn col;
                dgTurnos.AutoGenerateColumns = false;
                dgTurnos.Columns.Clear();

                DataGridViewCheckBoxColumn colChk = new DataGridViewCheckBoxColumn();
                colChk.DataPropertyName = "BOOLSINO";
                colChk.HeaderText = "Asistencia";
                colChk.Name = "chkSINO";
                colChk.Width = 80;
                colChk.ValueType = System.Type.GetType("System.Boolean");
                colChk.TrueValue = true;
                colChk.FalseValue = false;

                colChk.ReadOnly = false;
                dgTurnos.Columns.Add(colChk);

                col = new DataGridViewTextBoxColumn();
                col.DataPropertyName = "IDTURNO";
                col.Name = "IDTURNO";
                col.Width = 80;
                col.HeaderText = "N° Turno";
                col.ReadOnly = true;
                col.Visible = false;
                dgTurnos.Columns.Add(col);

                col = new DataGridViewTextBoxColumn();
                col.DataPropertyName = "FECHA";
                col.Name = "FECHA";
                col.Width = 80;
                col.HeaderText = "Fecha";
                col.ReadOnly = true;
                dgTurnos.Columns.Add(col);

                col = new DataGridViewTextBoxColumn();
                col.DataPropertyName = "HORA";
                col.Name = "HORA";
                col.Width = 60;
                col.HeaderText = "Hora";
                col.ReadOnly = true;
                dgTurnos.Columns.Add(col);

                col = new DataGridViewTextBoxColumn();
                col.DataPropertyName = "PROFESIONAL";
                col.Name = "PROFESIONAL";
                col.Width = 150;
                col.HeaderText = "Profesional";
                col.ReadOnly = true;
                dgTurnos.Columns.Add(col);

                col = new DataGridViewTextBoxColumn();
                col.DataPropertyName = "ESPECIALIDAD";
                col.Name = "ESPECIALIDAD";
                col.Width = 190;
                col.HeaderText = "Especialidad";
                col.ReadOnly = true;
                dgTurnos.Columns.Add(col);

                if (((DataTable)dgTurnos.DataSource).Rows.Count > 0)
                    dgTurnos.Rows[0].Selected = true;
 
            }
            catch
            {

            }
        }
    }
}
